import {onEnter, isWeiXin, isAndroid, setupWebViewJavascriptBridge, setItem} from '../../utils';
import Cookies from 'js-cookie';

module.exports = {
	path: 'sponsor',
	onEnter: ()=>{
        if (isAndroid()) {
            let token = Cookies.get('accesstoken');
            if (token) {
                setItem('token', token);
            }
        } else {
            setupWebViewJavascriptBridge(function (bridge) {
                bridge.registerHandler("accessTokenCallBack", function (data, responseCallback) {
                    let token = data.accesstoken;
                    if (token) {
                        setItem('token', token);
                    }
                })
            });
        }
	},
	childRoutes: [
		require('./photo'),
		require('./org'),
		require('./room')
	],
	indexRoute: {
		getComponent(location, cb) {
			require.ensure([], (require) => {
				cb(null, require('../../containers/sponsor/sponsor').default);
			})
		}
	}
};